using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SCSEngine.ScreenManagement.Implement;
using SCSEngine.ScreenManagement;
using SCSEngine.Control;
using SCSEngine.ResourceManagement;
using SCSEngine.Sprite;
using SCSEngine.Services;
using SVLvsXNA;
using SVLvsXNA.TriUanGame;
using Microsoft.Xna.Framework.Input;

namespace TriUan.TriUanGame.GameScreen
{
    public class MenuScreen : BaseGameScreen
    {
        private SCSServices engine;

        private Texture2D background;

        private Button playButton;
        private Button aboutButton;
        private Button optionButton;
        private Button helpButton;
        private Button creditButton;

        public MenuScreen(IGameScreenManager manager)
            : base(manager)
        {
            engine = (SCSServices)manager.GamePage.Services.GetService(typeof(SCSServices));

            IResourceManager resourceManager = (IResourceManager)manager.GamePage.Services.GetService(typeof(IResourceManager));

            background = resourceManager.GetResource<Texture2D>("MenuBackground");

            ISprite btPlayBackground = resourceManager.GetResource<ISprite>(Language.Prep + "Play");
            playButton = new Button(manager.GamePage, btPlayBackground);
            playButton.Position = new Vector2(600f, 250f);
            playButton.Size = new Vector2(btPlayBackground.SpriteData.Data.Texture.Width, btPlayBackground.SpriteData.Data.Texture.Height);
            playButton.OnTouched += new OnButtonTouchedHandler(playButton_OnTouched);

            ISprite btAboutBackground = resourceManager.GetResource<ISprite>("Ch_m Than");
            aboutButton = new Button(manager.GamePage, btAboutBackground);
            aboutButton.Position = new Vector2(600f, 400f);
            aboutButton.Size = new Vector2(btAboutBackground.SpriteData.Data.Texture.Width, btAboutBackground.SpriteData.Data.Texture.Height);
            aboutButton.OnTouched += new OnButtonTouchedHandler(aboutButton_OnTouched);

            ISprite btOptionBackground = resourceManager.GetResource<ISprite>("Options");
            optionButton = new Button(manager.GamePage, btOptionBackground);
            optionButton.Position = new Vector2(650f, 400f);
            optionButton.Size = new Vector2(btOptionBackground.SpriteData.Data.Texture.Width, btOptionBackground.SpriteData.Data.Texture.Height);
            optionButton.OnTouched += new OnButtonTouchedHandler(optionButton_OnTouched);

            ISprite btHelpBackground = resourceManager.GetResource<ISprite>("Question");
            helpButton = new Button(manager.GamePage, btHelpBackground);
            helpButton.Position = new Vector2(730f, 420f);
            helpButton.Size = new Vector2(btHelpBackground.SpriteData.Data.Texture.Width, btHelpBackground.SpriteData.Data.Texture.Height);
            helpButton.OnTouched += new OnButtonTouchedHandler(helpButton_OnTouched);

            ISprite btcreditBackground = resourceManager.GetResource<ISprite>("Credit");
            creditButton = new Button(manager.GamePage, btcreditBackground);
            creditButton.Position = new Vector2(500f, 400f);
            creditButton.Size = new Vector2(btcreditBackground.SpriteData.Data.Texture.Width, btcreditBackground.SpriteData.Data.Texture.Height);
            creditButton.OnTouched += new OnButtonTouchedHandler(creditButton_OnTouched);
        }

        void creditButton_OnTouched(Button sender, EventArgs args)
        {
            Manager.AddExclusive(Manager.Bank.GetScreen("Credit"));
        }

        void helpButton_OnTouched(Button sender, EventArgs args)
        {
            Manager.AddExclusive(Manager.Bank.GetScreen("Help"));
        }

        void optionButton_OnTouched(Button sender, EventArgs args)
        {
            Manager.AddExclusive(Manager.Bank.GetScreen("Options"));
        }

        void aboutButton_OnTouched(Button sender, EventArgs args)
        {
            Manager.AddExclusive(Manager.Bank.GetScreen("About"));
        }

        void playButton_OnTouched(Button sender, EventArgs args)
        {
            Manager.AddExclusive(Manager.Bank.GetScreen("GameMode"));
        }

        public override void Update(GameTime gameTime)
        {
            if (this.GamePage.IsBackKeyPress)
            {
            }

            playButton.Update(gameTime);
            optionButton.Update(gameTime);
            aboutButton.Update(gameTime);
            helpButton.Update(gameTime);
            creditButton.Update(gameTime);
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            engine.SpriteBatch.Draw(background, Vector2.Zero, Color.White);

            playButton.Draw(gameTime);
            optionButton.Draw(gameTime);
            aboutButton.Draw(gameTime);
            helpButton.Draw(gameTime);
            creditButton.Draw(gameTime);
            playButton.Draw(gameTime);
            base.Draw(gameTime);
        }
    }
}
